import { Component, Vue, Inject } from 'vue-property-decorator';

import { IUserAccount } from '@/shared/model/user-account.model';
import UserAccountService from './user-account.service';

@Component
export default class UserAccountDetails extends Vue {
  @Inject('userAccountService') private userAccountService: () => UserAccountService;
  public userAccount: IUserAccount = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.userAccountId) {
        vm.retrieveUserAccount(to.params.userAccountId);
      }
    });
  }

  public retrieveUserAccount(userAccountId) {
    this.userAccountService()
      .find(userAccountId)
      .then(res => {
        this.userAccount = res;
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
